package com.intellagric.controller.module.agriecom_merchant;

import com.intellagric.agriecom.module.agriecom_merchant.MerchantService;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.AgriecomMerchant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

@Controller
public class MerchantController {

    @Autowired
    private MerchantService merchantService;


    @RequestMapping("/merchant/add")
    @ResponseBody
    public ResponseMessage add(AgriecomMerchant merchant) {
        //设置默认数据
        merchant.setMerchantId(UUID.randomUUID().toString().replaceAll("-",""));
        merchant.setDelFlag("0");
        merchant.setCreateDate(new Date());
        merchant.setUpdateDate(new Date());
        return merchantService.addMerchant(merchant);
    }



    @RequestMapping("/merchant/delete")
    @ResponseBody
    public ResponseMessage delete(String id) { return merchantService.deleteMerchant(id); }

    @RequestMapping("/merchant/batchDelete")
    @ResponseBody
    public ResponseMessage batchDeleteMerchant(@RequestParam(value="ids[]") String[] ids) {

         return merchantService.batchDeleteMerchant(ids);
    }

    @RequestMapping("/merchant/edit")
    @ResponseBody
    public ResponseMessage edit(AgriecomMerchant merchant) {
        return merchantService.editMerchant(merchant);
    }


    @RequestMapping("/merchant/{id}")
    @ResponseBody
    public AgriecomMerchant get(@PathVariable String id) {
        return merchantService.getMerchantById(id);
    }


    @RequestMapping("/merchant/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return merchantService.getMerchantList();
    }

    @RequestMapping("/merchant/page")
    @ResponseBody
    public LayuiDataGridResult query(int page,int limit,String keyword){
        return  merchantService.getMerchantList(page,limit,keyword);

    }

}
